#!/usr/bin/python
#coding=utf-8
'''
lineplot by spacexi
version init
'''
import numpy as np
import matplotlib.pyplot as plt
import re
import os
import xlrd

def loadData_and_plot(flieName):  #读取xlsx文件同时将读取到的文件赋值给x和y并转化为float值
	data = xlrd.open_workbook(flieName)
	table = data.sheets()[0]
	ncols = table.ncols #获取列数
	for i in range(0,ncols,2):
		x=table.col_values(i)
		y=table.col_values(i+1)
		x=Tofloat(x)
		y=Tofloat(y)
		plt.plot(x, y, color=line_color(i//2),marker=marker_type(i//2),linewidth=1,label=local_label[i//2])
	return 0

def Tofloat(x):# 转化为float数值
	for j in range(len(x)):
			x[j]=float(x[j])
	return x
	
def line_color(color_number):#用来设定不同曲线的颜色，超过8个曲线之后颜色会有相同
	if color_number>=8: color_number=colornumber%8
	color_list=['black','blue','green','red','m','olive','coral','crimson']
	return color_list[color_number]
	
def marker_type(marker_type_number):#用来设定不同的数据点类型
	if marker_type_number>=8: marker_type_number=marker_type_number%8
	marker_type_list=['o','v','s','h','p','8','^','*']
	return marker_type_list[marker_type_number]	

ax = plt.subplot(111) 
local_label=['k','R-square']#此处按顺序修改图题，用英文逗号隔开
loadData_and_plot('data.xlsx')
plt.xlabel('x') #此处修改x轴名称
plt.ylabel('y') #此处修改y轴名称
#plt.xlim(30,70) # 此处设置x范围范围，若启用该设置请删去最前方#
#plt.ylim(30,70) # 此处设置y范围范围，若启用该设置请删去最前方#
ax.tick_params(direction='in')
#ax.set_title('XRD Result') # 此处设置图题，若启用该设置请删去最前方#
plt.legend(loc="upper right",edgecolor='none')# 此处设置图例位置
plt.show()
